<!-- xuwencheng  2022年6年29日18:00  这是我的wenzhangbianji -->
<!-- 编辑 -->
<template>
  <el-dialog
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :destory-on-close="true"
    :title="title"
    :visible.sync="dialogFormVisible"
    width="65%"
    @close="close"
  >
    <el-form ref="form" label-width="200px" :model="form">
      <el-form-item label="幻灯片名称" prop="slideShowName">
        <el-input v-model="form.slideShowName" placeholder="请输入幻灯片名称" />
      </el-form-item>

      <el-form-item label="幻灯片图片" prop="slideShowUrl">
        <el-input v-model="form.slideShowUrl" style="display: none" />
        <el-upload
          v-model="form.slideShowUrl"
          action="https://star.gengduoke.com/adminapi/file/commonupload"
          :before-upload="beforeAvatarUpload"
          class="avatar-uploader"
          :headers="{
            'X-Token': token,
          }"
          :on-success="handleAvatarSuccess"
          :show-file-list="false"
        >
          <img v-if="imageUrl" class="avatar" :src="imageUrl" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="链接类型" prop="slideShowType">
        <el-radio v-model="form.slideShowType" label="0">菜单</el-radio>
        <el-radio v-model="form.slideShowType" label="1">页面</el-radio>
        <el-radio v-model="form.slideShowType" label="2">h5</el-radio>
      </el-form-item>
      <el-form-item label="链接" prop="skipPath">
        <el-input v-model="form.skipPath" placeholder="请输入跳转路径" />
      </el-form-item>

      <el-form-item label="状态" prop="block">
        <el-radio v-model="form.block" label="0">停用</el-radio>
        <el-radio v-model="form.block" label="1">启用</el-radio>
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input v-model="form.sort" placeholder="请输入排序" />
      </el-form-item>
    </el-form>
    <el-button class="baocun" size="medium" type="primary" @click="save">
      保存
    </el-button>
  </el-dialog>

  <!-- 增加 -->
</template>

<script>
  /* eslint-disable*/
  import { doEdit } from '@/api/lunbotu'
  import {
    provinceAndCityData,
    regionData,
    provinceAndCityDataPlus,
    regionDataPlus,
    CodeToText,
    TextToCode,
  } from 'element-china-area-data'
  //import { number } from 'echarts'
  export default {
    name: 'search',

    data() {
      return {
        options: regionDataPlus,
        selectedOptions: [],
        token: '',
        imageUrl: '',
        value: true,
        value1: true,
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false,
        options1: [],
        options2: [],
        options3: [],
        valueone: '',
        valuetwo: '',
        form: {
          cityId: '', //chengshiid
          sort: 0,
          roles: [],
          displayLocked: true,
          recommendLocked: true,
          share: true,
          locked: false,
          crewThemeId: '', //剧组题材id
          surfacePlot: '',
          crewTheme: '', //剧组题材
          cityName: '', //城市名
          areaName: '', //区域名称
          areaId: '', //区域id
        },
        activated() {
          if (this.$refs.MaskVideo.src) this.$refs.MaskVideo.play()
        },
        deactivated() {
          if (this.$refs.MaskVideo.src) this.$refs.MaskVideo.pause()
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    methods: {
      handleAvatarSuccess(res, file, fileList) {
        this.imageUrl = URL.createObjectURL(file.raw)
        console.log(res)
        this.form.surfacePlot = res.data
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg'
        const isLt2M = file.size / 1024 / 1024 < 2
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!')
        }
        return true
      },

      showEdit(row) {
        if (!row) {
          this.title = '添加'
        } else {
          this.title = '编辑'
          this.form = Object.assign({}, row)
          console.log(row)
          this.form.block = String(row.block)
          this.form.slideShowType = String(row.slideShowType)
          this.imageUrl = row.slideShowUrl
        }

        this.dialogFormVisible = true
      },
      close() {
        let userId = this.form.userId
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        if (!this.form.id) {
          this.form.userId = userId
        }
        console.log(this.form)
        this.dialogFormVisible = false
        this.imageUrl = ''
        // this.form = ''
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await doEdit(this.form)
            this.$baseMessage(msg, 'success', 'vab-hey-message-success')
            this.$emit('fetch-data')
            this.close()
          }
        })
      },
    },
  }
</script>
<style>
  /* .huakuai {
    position: relative;
    left: 96%;
  } */
  .avatar-uploader .el-upload {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    width: 178px;
    height: 178px;
    font-size: 28px;
    line-height: 178px;
    color: #8c939d;
    text-align: center;
  }
  .avatar {
    display: block;
    width: 178px;
    height: 178px;
  }
  .baocun {
    width: 100%;
    height: 100%;
  }
</style>
